using System;
using UnityEngine;

namespace HEFramework
{
    /// <summary>
    ///
    /// Resources资源模式
    /// 
    /// ----------------------------------------
    /// 作者 hep
    /// 创建时间：2023-01-16 19:39:26
    /// ----------------------------------------
    /// </summary>
    public class Resources_AssetLoad : IAssetLoad
    {
        public T LoadAssetSyn<T>(string _assetBundleName, string _assetName, string _extension) where T : UnityEngine.Object
        {
            string assetBundleName = _assetBundleName.ToLower();
            string filePath = assetBundleName + "/" + _assetName;
            return Resources.Load<T>(filePath);
        }

        public void LoadAssetAsync<T>(string _assetBundleName, string _assetName, string _extension, Action<T> _callback) where T : UnityEngine.Object
        {
            string assetBundleName = _assetBundleName.ToLower();
            string filePath = assetBundleName + "/" + _assetName;
            LoadAsync(filePath, _callback).Coroutine();
        }

        public void UnLoadAssetAsync(string _assetBundleName)
        {
        }

        private async HETask LoadAsync<T>(string _filePath, Action<T> _callback) where T : UnityEngine.Object
        {
            var request = Resources.LoadAsync<T>(_filePath);
            await request;
            _callback.Invoke((T)request.asset);
        }
    }
}